package ar.com.photo_admin.domain

import org.apache.commons.httpclient.HttpState;
import org.apache.commons.httpclient.HttpStatus;

import grails.plugins.springsecurity.Secured

class MPNotificationController {

	def payingService
	
    def notification() { 
		log.info "Recibiendo notificacion de MP"		
		def topic = params.topic
		def notifId = params.id;
		
		Photographer photographer = Photographer.get(params.photographerId)
		
		if(topic == 'payment' && photographer!=null){
			log.info "Se ha recibido la notificacion ${notifId} para el fotografo #${photographer.id}"
			payingService.registerNotification(notifId,photographer.clientId,photographer.clientSecret); 					
		}
		else{
			log.error "No se pudo registrar la notificacion: "
			log.error "Topic: ${topic} "
			log.error "Notification ID: ${notifId} "
			log.error "Photographer ID: ${params.photographerId} "
		}
				
		render true;
		return;
	}
}
